home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
pascal
/
bitmbtn.exe
/
BUTTONS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-11-13
|
14KB
|
368 lines
Unit Buttons;
{***************************************************************************}
{* Buttons.pas by Daniel Thomas (CIS: 72301,2164) *}
{* *}
{* This code is hereby donated to tbe Public Domain. Have fun! *}
{* *}
{* *}
{* There are 2 kinds of Button objects in this library. Both of them *}
{* are for creating buttons made up of bitmaps. The first object uses *}
{* only one bitmap, and draws any needed "effects". The second object *}
{* uses three bitmaps, one for each state (up, down, and disabled). *}
{* *}
{* Neither of these objects supports drawing on Dialogs, but it's a *}
{* start! Also, neither of these buttons looks any different if it's *}
{* the default button. Again, you're on your own! *}
{* *}
{* For either type of button, just Init the object in the parent's Init *}
{* method, and you've got a button! If you want to create it in some *}
{* other method than the parent's Init method, use Application^.MakeWindow *}
{* to make it visible. *}
{* *}
{* Add a method to the parent window, like this: *}
{* *}
{* Procedure wmDrawItem(var Msg:tMessage);virtual wm_First+wm_DrawItem; *}
{* *}
{* It should look like this: *}
{* *}
{* Procedure tMainWindow.wmDrawItem(var Msg:tMessage); *}
{* begin *}
{* with pDrawItemStruct(Msg.lParam)^ do *}
{* case CtlType of *}
{* odt_Button: *}
{* case CtlID of *}
{* id_Button1 : Button1^.DrawItem(Msg); *}
{* id_Button2 : Button2^.DrawItem(Msg); *}
{* end; *}
{* end; *}
{* end; *}
{* *}
{* *}
{* tSingleBitmapButton *}
{* *}
{* Two Init methods. The second one allows you to specify the color *}
{* of a surrounding box. *}
{* *}
{* Specify the parent object (@self), an ID number, the location of *}
{* the button (x & y), whether it's the default, and the name of the *}
{* bitmap. (The second Init method also let's you specify an RGB *}
{* color for a border). *}
{* *}
{* Create the bitmap as large as the button needs to be, minus the *}
{* surrounding black box. It is assumed that the button's "background" *}
{* color is light gray. The "shading" effects will be drawn for you. *}
{* *}
{* tMultiBitmapButton *}
{* *}
{* Specify the parent object (@self), an ID number, the location of *}
{* the button (x & y), whether it's the default, and the name of the *}
{* three bitmaps (one for a non-pressed button, one for a pressed *}
{* button, and one for a disabled button). ALL THREE MUST BE THE SAME *}
{* SIZE. *}
{* *}
{***************************************************************************}
interface
uses WinTypes,WinProcs,WObjects;
type
pSingleBitmapButton=^tSingleBitmapButton;
tSingleBitmapButton=object(tButton)
Bitmap : hBitmap;
UseSpecialBorder : boolean;
SpecialBorderColor : longint;
constructor Init(aParent: pWindowsObject; aID: Integer;
X,Y: Integer; IsDefault: Boolean;
aBitmap: pChar);
constructor InitWithSpecialBorder(
aParent: pWindowsObject; aID: Integer;
X,Y: Integer; IsDefault: Boolean;
aBitmap: pChar;
aSpecialBorderColor: longint);
destructor Done; virtual;
procedure DrawItem(var Msg:tMessage); virtual;
end;
pMultiBitmapButton=^tMultiBitmapButton;
tMultiBitmapButton=object(tButton)
NormalBitmap,
DownBitmap,
DisabledBitmap : hBitmap;
constructor Init(aParent: pWindowsObject; aID: Integer;
X,Y: Integer; IsDefault: Boolean;
aNormalBitmap,aDownBitmap,aDisabledBitmap: pChar);
destructor Done; virtual;
procedure DrawItem(var Msg:tMessage); virtual;
end;
implementation
const
cBlackColor = $00000000;
cWhiteColor = $00FFFFFF;
cDarkGrayColor = $00808080;
cLightGrayColor = $00C0C0C0;
type
pDrawItemStruct = ^tDrawItemStruct;
var
bmp : hBitmap;
{**************************************************************************}
{* tSingleBitmapButton *}
{**************************************************************************}
constructor tSingleBitmapButton.Init(aParent: pWindowsObject; aID: Integer;
X,Y: Integer; IsDefault: Boolean;
aBitmap: pChar);
var
bm : tBitMap;
w,h : integer;
begin
bmp := LoadBitmap(hInstance,aBitmap);
GetObject(bmp,sizeof(bm),@bm);
tButton.Init(aParent,aID,'Dummy',x,y,bm.bmWidth+2,bm.bmHeight+2,IsDefault);
Attr.Style := Attr.Style or bs_OwnerDraw;
Bitmap := bmp;
UseSpecialBorder := false;
end; {tSingleBitmapButton.Init}
constructor tSingleBitmapButton.InitWithSpecialBorder(
aParent: pWindowsObject; aID: Integer;
X,Y: Integer; IsDefault: Boolean;
aBitmap: pChar;
aSpecialBorderColor: longint);
var
bm : tBitMap;
w,h : integer;
begin
bmp := LoadBitmap(hInstance,aBitmap);
GetObject(bmp,sizeof(bm),@bm);
tButton.Init(aParent,aID,'Dummy',x,y,bm.bmWidth+4,bm.bmHeight+4,IsDefault);
Attr.Style := Attr.Style or bs_OwnerDraw;
Bitmap := bmp;
UseSpecialBorder := true;
SpecialBorderColor := aSpecialBorderColor;
end; {tSingleBitmapButton.Init}
destructor tSingleBitmapButton.Done;
begin
tButton.Done;
DeleteObject(Bitmap);
end; {tSingleBitmapButton.Done}
procedure tSingleBitmapButton.DrawItem(var Msg: tMessage);
var
Down : boolean;
OldMode,
w,h,x1,y1 : integer;
MemDC : hDC;
OldBmp : hBitmap;
Pts : array[0.